(function($) {
		  
	$.fn.select_autocomplete = function(options) {
		
		// make sure we have an options object
		options = options || {};
		
		// setup our defaults
		var defaults = { 
			  minChars: 0
			, width: 310
			, matchContains: true
			, autoFill: false
			, formatItem: function(row, i, max) {
				return row.name;
			}
			, formatMatch: function(row, i, max) {
				return row.name;
			}
			, formatResult: function(row) {
				return row.name;
			}
		};
		
		options = $.extend(defaults, options);
		
		return this.each(function() {
		
			//stick each of it's options in to an items array of objects with name and value attributes 
			var $this = $(this),
				data = [],
				$input = $('<input type="text" class="autocomplete-text"/>');
			
			if (this.tagName.toLowerCase() != 'select') { return; }
				
			
			$this.children('option').each(function() {
		
				var $option = $(this);
				
				if ($option.val() != '') { //ignore empty value options

					data.push($option.html());
				}
			});
			
			// insert the input after the select
			$this.after($input);
			$this.hide();
			
			// add it our data
			options.data = data;
			//make the input box into an autocomplete for the select items
			$input.autocomplete({
				source:data,
				select:function(event, ui) {
					//$this.children('option:first').attr('selected', true);
					$this.children('option:contains("' + ui.item.value + '")').attr('selected', true);
				},
				search:function() {
					$this.children('option:first').attr('selected', true);
				},
				minLength:2
			});
			$input.keyup(function() {
			
				if($(this).val().length < 2) {
					$this.children('option:first').attr('selected', true);
				}
			});
		});


	};		  
  
})(jQuery);